package com.wenda.homeschooedu.daoimpl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.wenda.homeschooedu.DB.DB;
import com.wenda.homeschooedu.DB.JDBCConnection;
import com.wenda.homeschooedu.dao.IExamPlan;
import com.wenda.homeschooedu.model.ExamPlan;

public class ExamPlanService implements IExamPlan {
	private JDBCConnection jdbc;
	private Connection connection;
	private Statement statement;

	public ExamPlanService() {
		this.jdbc = new JDBCConnection();
		this.connection = jdbc.getConn();
		this.statement = jdbc.getStm();
	}

	public List<ExamPlan> getExamPlans() {
		String sql = String.format(DB.Table.Examplan.SQL.SELECT, "1=1");
		List<ExamPlan> examPlans = new ArrayList<ExamPlan>();
		try {
			ResultSet resultSet = statement.executeQuery(sql);
			
			if (resultSet != null) {
				while (resultSet.next()) {
					ExamPlan examPlan = new ExamPlan();
					examPlan.set_id(resultSet.getInt(resultSet.findColumn("_id")));
					examPlan.setDecription(resultSet.getString(resultSet.findColumn("description")));
					examPlan.setExam_id(resultSet.getInt(resultSet.findColumn("exam_id")));
					examPlan.setExam_name(resultSet.getString(resultSet.findColumn("exam_name")));
					examPlan.setThetime(resultSet.getString(resultSet.findColumn("theTime")));
					examPlans.add(examPlan);
					
					
				}
				
			}

			return examPlans;

		} catch (SQLException e) {
			// TODO Auto-generated catch block

			e.printStackTrace();
			return null;
		} finally {
			try {
				statement.close();

				connection.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}

}
